<template>
  <div class="container">
    <el-dialog
        title="新增"
        :visible.sync="centerDialogVisible"
        width="30%"
        center>
      <el-form label-position="right" label-width="80px">
        <el-form-item label="角色名称">
          <el-input v-model="roleInfo.name" placeholder="请输入角色名称"></el-input>
        </el-form-item>
        <el-form-item label="角色编码">
          <el-input v-model="roleInfo.code" placeholder="请输入角色编码"></el-input>
        </el-form-item>
        <el-form-item label="备注">
          <el-input v-model="roleInfo.remark" placeholder="请输入备注"></el-input>
        </el-form-item>
        <el-form-item label="状态">
          <el-select v-model="roleInfo.status" placeholder="请选择状态">
            <el-option
                v-for="item in options"
                :key="item.value"
                :label="item.label"
                :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
    <el-button @click="centerDialogVisible = false">取 消</el-button>
    <el-button type="primary" @click="submitAdd">确 定</el-button>
  </span>
    </el-dialog>
  </div>
</template>
<script>
import api from '@/utils/api';
import * as echarts from "echarts";
import axios from 'axios'
import data from "@/assets/data1.json";

export default {
  mounted() {
  },
  data() {
    return {
      centerDialogVisible: false,
      roleInfo: {
        name: '',
        code: '',
        remark: '',
        status: null
      },
      options: [
        {
          value: 1,
          label: '有效'
        }, {
          value: 0,
          label: '无效'
        }],
    }
  },
  methods: {
    open() {
      this.centerDialogVisible = true
    },
    clear() {
      this.roleInfo.code = ''
      this.roleInfo.name = ''
      this.roleInfo.remark = ''
      this.roleInfo.status = null
    },
    submitAdd() {
      const self = this
      const obj = {}
      obj.name = self.roleInfo.name
      obj.code = self.roleInfo.code
      obj.remark = self.roleInfo.remark
      obj.status = self.roleInfo.status
      api.addRoleInfo(obj).then((data) => {
        if (data.code == 200) {
          self.$message({
            type: "success",
            message: "创建成功!",
          });
          self.centerDialogVisible = false;
          self.$emit("afterSubmit");
          self.clear()
        } else {
          self.$message.error(data.msg);
        }
      })
    },
    getRoleList() {
      api.roleSelectList()
          .then(res => {
            if (res.code == 200) {
              this.userRoleList = res.data
            }
          })
    },
  }
};
</script>
<style scoped>


</style>